package com.bytz.modules.cms.statistic.controller;

import com.bytz.common.api.vo.Result;
import com.bytz.modules.cms.order.model.OrderEndUserStatistic;
import com.bytz.modules.cms.order.model.ProductLineStatisticResult;
import com.bytz.modules.cms.statistic.model.DateRangeModel;
import com.bytz.modules.cms.statistic.model.RecentOrderCount;
import com.bytz.modules.cms.statistic.model.TurnoverRequest;
import com.bytz.modules.cms.statistic.service.IStatisticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "首页")
@RequestMapping("/statistic")
public class StatisticController {

    @Autowired
    private IStatisticService statisticService;

    @ApiOperation("近期订单数量统计")
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    public Result<RecentOrderCount> recentOrderCount() {
        return Result.ok(statisticService.recentOrderCount());
    }

    @ApiOperation("订单组成")
    @RequestMapping(value = "/pieChart", method = RequestMethod.GET)
    public Result<List<OrderEndUserStatistic>> pieChart() {
        return Result.ok(statisticService.pieChart());
    }

    @ApiOperation("交易额曲线")
    @RequestMapping(value = "/lineChart", method = RequestMethod.POST)
    public Result<List<DateRangeModel>> lineChart(@RequestBody TurnoverRequest turnoverRequest) {
        return Result.ok(statisticService.lineChart(turnoverRequest));
    }

    @ApiOperation("各产品线销售额")
    @RequestMapping(value = "/productLineTotal", method = RequestMethod.GET)
    public Result<List<ProductLineStatisticResult>> productLineTotal() {
        return Result.ok(statisticService.productLineTotal());
    }
}
